package satir.card;

import java.util.ArrayList;
import org.json.JSONArray;
import satir.command.AskQuestionCmd;
import satir.player.Player;

/**
 * The Class EventCard.
 * @version 3.0 April 2012
 * @author Creative Family
 */
public class EventCard extends ActionCard {

    /**
     * Instantiates a new event card.
     * @param key
     *            the key
     * @param name
     *            the name
     * @param questions
     *            the questions
     */
    public EventCard(final String key, final String name, final ArrayList<Question> questions) {
	super(key, name, questions);
    }

    /**
     * Check the user want to use tool or not first If not, loop the questions
     * and create a command to ask question, After that, put the command into
     * record.
     * @param player
     *            the player that activate this card
     */
    @Override
    protected void doActivateCard(final Player player) {
	boolean isUseTool = useMagicTool(player, "EventCard");
	System.out.println("");
	if (!isUseTool) {
	    for (int i = 0; i < questions.size(); i++) {
		AskQuestionCmd cmd = new AskQuestionCmd(questions.get(i),
			player);
		cmd.execute();
		record.add(cmd);
	    }
	}
    }

    /**
     * Gets the key.
     * @return key
     */
    @Override
    public String getKey() {
	return key;
    }

    /**
     * Gets class type.
     * @return class type
     */
    @Override
    public String getClassType() {
	return "EventCard";
    }

    /**
     * Gets card action.
     * @return card action detail
     */
    @Override
    public String getAction() {
	JSONArray actionJson = new JSONArray();
	for (int i = 0; i < questions.size(); i++) {
	    actionJson.put(record.get(i).getChoice().getContent());
	}
	return actionJson.toString();
    }

    /**
     * Gets player name.
     * @return player name
     */
    @Override
    public String getPlayer() {
	return record.get(0).getPlayer().getName();
    }
}
